#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 25;
string word[N];
int used[N];
int min_repeat[N][N];
int n;
int ans;

void dfs(string dragon, int u)
{
	ans = max(ans, (int)dragon.size());
	used[u]++;
	for (int i = 0; i < n; i++) {
		if (min_repeat[u][i] && used[i] < 2) {
			dfs(dragon + word[i].substr(min_repeat[u][i]), i);
		}
	}
	used[u]--;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> word[i];
	}
	char star;
	cin >> star;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 1; k < min(word[i].size(), word[j].size()); k++) {
				if (word[i].substr(word[i].size() - k , k) == word[j].substr(0, k)) {
					min_repeat[i][j] = k;
					break;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (word[i][0] == star) {
			dfs(word[i], i);
		}
	}
	cout << ans << endl;
	return 0;
}